<template>
  <div>
    <div class="city-title">热门城市</div>
    <div class="hot" v-if="hotCity">
      <div
        class="city-hot-item"
        v-for="value in hotCity.cities"
        :key="value.cityId"
        @click="goHome(value)"
      >
        {{ value.name }}
      </div>
    </div>

    <div v-for="item in otherCity" :key="item.prefix">
      <div class="city-title">{{ item.prefix }}</div>
      <div
        class="city-item"
        v-for="value in item.cities"
        :key="value.cityId"
        @click="goHome(value)"
      >
        {{ value.name }}
      </div>
    </div>
  </div>
</template>

<script>
import { mapMutations, mapActions, mapGetters } from "vuex";
export default {
  computed: mapGetters("city", ["hotCity", "otherCity"]),
  mounted() {
    this.getCityListAsync();
  },
  methods: {
    ...mapMutations("city", ["changeCity"]),
    ...mapActions("city", ["getCityListAsync"]),
    goHome(v) {
      this.changeCity(v);
      this.$router.push("/home");
    },
  },
};
</script>

<style lang="less" scoped>
@import "../../assets/css/var.less";
.city-title {
  padding-left: 20px;
  background-color: #ebebeb;
  font-size: 14px;
  color: #333;
  height: 30px;
  line-height: 30px;
  width: 100%;
}
.city-item {
  height: 40px;
  line-height: 40px;
  margin-left: 20px;
  border-bottom: 1px solid #c8c7cc;
  font-size: 16px;

  &:last-child {
    border: none;
  }
}

.hot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-evenly;
  .city-hot-item {
    border: 1px solid #c8c7cc;
    width: 30%;
    .ell();
    margin: 10px 0;
    font-size: 14px;
    text-align: center;
    line-height: 30px;
  }
}
</style>
